﻿//=============================================================================
// Project  : NIPO Component Framework
// File    : GenericDTO.cs
// Author  : Bernhard Dieber (Bernhard.Dieber@uni-klu.ac.at)
// Copyright 2010 by Bernhard Dieber
// This code is published under the Microsoft Public License (Ms-PL).  A copy
// of the license should be distributed with the code.  It can also be found
// at the project website: http://NIPO.CodePlex.com.   This notice, the
// author's name, and all copyright notices must remain intact in all
// applications, documentation, and source files.
//=============================================================================

using System;
using System.Collections.Generic;
using System.Text;

namespace NIPO.Data
{
    /// <summary>
    /// Implementation of the <see cref="DataTransferObject" /> class to support generic data transfer
    /// </summary>
    /// <typeparam eventName="T">Denotes the type of data contained in a certain instance</typeparam>
    public class GenericDTO<T>:DataTransferObject
    {
        private T _value;

        /// <summary>
        /// Initializes a new instance of the <see cref="GenericDTO&lt;T&gt;"/> class.
        /// </summary>
        /// <param eventName="value">The value for this buffer object.</param>
        /// <param eventName="contentDescription">The content description.</param>
        /// <param eventName="contentSize">Size of the content.</param>
        /// <param eventName="timestamp">The timestamp.</param>
        public GenericDTO(T value, string contentDescription, long contentSize, DateTime timestamp) : base(typeof(T), contentDescription, contentSize, timestamp)
        {
            _value = value;
        }

        /// <summary>
        /// Gets the value of this DTO.
        /// </summary>
        /// <value>The data contained in this DTO.</value>
        public T Value
        {
            get { return _value; }
        }

        /// <summary>
        /// Performs an explicit conversion from <see cref="NIPO.Data.GenericDTO&lt;T&gt;"/> to the given class.
        /// </summary>
        /// <param eventName="source">The source.</param>
        /// <returns>The result of the conversion.</returns>
        public static explicit operator T(GenericDTO<T> source)
        {
            return source.Value;
        }
    }
}